package com.fourth.controller.api;

import com.fourth.service.SortService;
import com.fourth.vo.BrandVo;
import com.ljx.entity.Sort;
import com.ljx.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiaoZhu
 * @version 1.0
 * @date 2023/2/27 21:54
 */
@Api(value = "commodity/api/sort", tags = {""})
@RestController
@RequestMapping("commodity/api/sort")
public class ApiSortController {
    @Autowired
    private SortService sortService;

    /**
     * 查询全部类别
     * @param currentPage
     * @param pageSize
     * @param
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "Sort", name = "sort", value = "", required = true)
    })
    @ApiOperation(value = "查询全部类别", notes = "查询全部类别", httpMethod = "POST")
    @PostMapping("/select")
    public Result selectAll(
            @RequestParam(defaultValue = "1") Integer currentPage,
            @RequestParam(defaultValue = "5") Integer pageSize,
            @RequestBody Sort sort
    ){
        return sortService.selectAll(currentPage,pageSize,sort);
    }

    /**
     * 审核验证
     * @param sort
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Sort", name = "sort", value = "", required = true)
    })
    @ApiOperation(value = "审核验证", notes = "审核验证", httpMethod = "POST")
    @PostMapping("/update")
    @ResponseBody
    public Result update(@RequestBody Sort sort){
        System.out.println("sort = " + sort);
        boolean b = sortService.updateById(sort);
        if (b==true){
            return new Result(200,"审核成功");
        }
        return new Result(500,"审核失败");
    }

    /**
     * 根据id删除类别
     * @param Id
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "Id", value = "", required = true)
    })
    @ApiOperation(value = "根据id删除类别", notes = "根据id删除类别", httpMethod = "POST")
    @PostMapping("/delece")
    public Result delece(Integer Id){
        boolean b = sortService.removeById(Id);
        if (b==true){
            return new Result(200,"删除成功");
        }
        return new Result(500,"删除失败");
    }
}
